<template>
  <div class="esign">
    <div class="esign-box">
      <vue-esign
        class="sign1"
        ref="esign"
        :width="800"
        :height="300"
        :isCrop="isCrop"
        :lineWidth="lineWidth"
        :lineColor="lineColor"
        :bgColor.sync="bgColor"
      />
    </div>
    <div class="esigh-btns">
      <button @click="handleReset">清空画板</button>
      <button @click="handleGenerate">确认</button>
    </div>
    <div class="esigh-result">
      <img v-if="result.resultImg" :src="result.resultImg" alt="" />
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import vueEsign from "vue-esign";
Vue.use(vueEsign);
import * as sf from '@/api/harvest/sf.js';
import qs from 'qs'

export default {
  name: "ContractSign",
  data() {
    return {
      lineWidth: 6,
      lineColor: "#000000",
      bgColor: "",
      result: {
        resultImg: '',
        path: 'sign.jpg',
      },
      isCrop: false,
      borders: "1px solid red",
      contractForm:{}
    };
  },

  methods: {
    handleReset() {
      this.$refs.esign.reset();
    },
    handleGenerate() {
      this.$refs.esign
        .generate()
        .then((res) => {
          this.result.resultImg = res;
          sf.generateSignImg(this.result).then(res=>{
            this.$message.success("特别提示:请您仔细阅读合同条款");
          });
          /*sf.generateContractPdf(this.contractForm).then(res=>{
            console.log(res);
            this.$message.success("ok");
          })*/
          let data = qs.stringify({
            ownerName: this.contractForm.ownerName,
            ownerIdCard: this.contractForm.ownerIdCard,
            signUserName: this.contractForm.signUserName,
            signUserIdCard: this.contractForm.signUserIdCard,
            premiseName: this.contractForm.premiseName,
            houseName: this.contractForm.houseName,
            countMonth: this.contractForm.countMonth,
            leaseStartTime: this.contractForm.leaseStartTime,
            leaseEndTime: this.contractForm.leaseEndTime,
            depositMoney: this.contractForm.depositMoney,
            depositType: this.contractForm.depositType,
            monthRent: this.contractForm.monthRent,
            paymentType: this.contractForm.paymentType
          });

          window.location.href = "http://localhost:8080/shoufang/contract/generateContractPdf?"+data;
        })
        .catch((err) => {
          alert(err);
          // 画布没有签字时会执行这里 'Not Signned'
        });
    },
  },
  mounted() {
    this.contractForm = this.$route.params.contractForm;
  }
};
</script>

<style scoped>
.esign {
  max-width: 1000px;
  margin: auto;
  padding: 10px;
  border: 1px solid rebeccapurple;
}
.esigh-btns button {
  color: #fff;
  height: 40px;
  width: 100px;
  font-size: 16px;
  margin-right: 10px;
  outline: none;
  border-radius: 4px;
  background: #f60;
  border: 1px solid transparent;
}
.esigh-btns button:active {
  color: #fff;
  box-shadow: 0px 0px 50px orangered inset;
}
.esigh-result {
  margin-top: 10px;
}
.esigh-result img {
  display: block;
  /* max-width: 100%; */
  /* height: auto; */
  max-width: 50%;
  height: 50%;
  margin: auto;
  left: 50%;
  transform: rotateX(50%);
  border: 1px solid #ececee;
}
.esignature {
  margin: 10px 0;
  border: 2px solid #ccc;
}
</style>
